import { Component, OnInit, ViewChild } from '@angular/core';
import { STComponent, STColumn, STRequestOptions, STChange } from '@delon/abc/st';
import { SFComponent, SFSchema } from '@delon/form';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-add-owner',
  templateUrl: './add-owner.component.html'
})
export class AddOwnerComponent implements OnInit {
  data = [];
  selectedData: any[] = [];
  @ViewChild('st', { static: true })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  columns: STColumn[] = [
    { title: '', index: 'key', type: 'checkbox' },
    { title: '企业名称', index: 'enterpriseName' },
    { title: '联系人姓名', index: 'contacter' },
    { title: '联系人手机号', index: 'mobile' },
    {
      title: '认证状态',
      index: 'approvalStatus',
      type: 'enum',
      enum: { 1: '未上传', 0: '草稿', 10: '待审核', 20: '已审核', 30: '已驳回', 40: '证件过期' }
    }
  ];
  searchSchema: SFSchema = {
    properties: {
      enterpriseName: {
        title: '',
        type: 'string',
        ui: {
          placeholder: '请输入企业名称'
        }
      },
      contactName: {
        title: '',
        type: 'string',
        ui: {
          placeholder: '请输入姓名'
        }
      },
      mobile: {
        title: '',
        type: 'string',
        ui: {
          placeholder: '请输入手机号'
        }
      }
    }
  };

  constructor(public service: TicketService) {}

  ngOnInit(): void {}

  beforeReq = (requestOptions: STRequestOptions) => {
    Object.assign(requestOptions.body, {
      listSource: 2,
      approvalStatus: '20'
    });
    if (this.sf) {
      Object.assign(requestOptions.body, {
        ...this.sf?.value
      });
    }
    return requestOptions;
  };

  stChange(e: STChange): void {
    switch (e.type) {
      case 'checkbox':
        this.selectedData = e.checkbox!;
        break;
    }
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
  }
}
